package domain

import (
	"context"
	"fmt"
)

type Demo struct {
	Id     string
	BillNo string
	Items  []*DemoItem
}

type DemoItem struct {
	Id     string
	DemoId string
	ItemNo string
}

func NewDemo(id string, billNo string) (*Demo, error) {
	if id == "" {
		return nil, fmt.Errorf("id是必须的")
	}
	if billNo == "" {
		return nil, fmt.Errorf("billNo是必须的")
	}
	return &Demo{
		Id:     id,
		BillNo: billNo,
		Items:  make([]*DemoItem, 0),
	}, nil
}

func (d *Demo) AddItem(itemId string, itemNo string) error {
	d.Items = append(d.Items, &DemoItem{
		Id:     d.Id,
		DemoId: itemId,
		ItemNo: itemNo,
	})
	return nil
}

type DemoRepository struct {
	sqlGdbc SqlGdbc
}

func NewDemoRepository(sqlGdbc SqlGdbc) *DemoRepository {
	return &DemoRepository{sqlGdbc}
}

func (r *DemoRepository) GetList(ctx context.Context, billNo string, itemNo string, pageIndex int, pageSize int) (list []*Demo, count int64, err error) {
	return nil, 0, nil
}

func (r *DemoRepository) Insert(ctx context.Context, entity *Demo) error {

	//insert demo

	//range insert demo item

	return nil
}

func (r *DemoRepository) Update(ctx context.Context, entity Demo) error {

	//update demo

	//range update demo item

	return nil
}

func (r *DemoRepository) Delete(ctx context.Context, id string) error {

	//range delete demo item

	//delete demo

	return nil
}
